<%@ page autoFlush="false" language="java" import="java.awt.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*" pageEncoding="UTF-8"%>
<%@ page import="beans.*"%> 
<% 
RandomStringUtils rs=new RandomStringUtils(); 
String random=rs.randomAlphanumeric(4); 
session.setAttribute("random",random); 
%> 
<% 
out.clear(); 
response.setContentType("image/jpeg"); 
response.addHeader("pragma","NO-cache"); 
response.addHeader("Cache-Control","no-cache"); 
response.addDateHeader("Expries",0); 
int width=60, height=18; 
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 
Graphics g = image.getGraphics(); 
//以下填充背景色 
g.setColor(Color.white); 
Font DeFont=new Font("SansSerif", Font.PLAIN, 18); 
g.setFont(DeFont); 
g.fillRect(0, 0, width, height); 
//字体色 
g.setColor(Color.blue); 
g.drawString(random,2,15); 
g.dispose(); 
ServletOutputStream outStream = response.getOutputStream(); 
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(outStream); 
encoder.encode(image); 
System.out.print("=image="+image);
outStream.close(); 
%> 